package com.zabra.zl.ui.login.presenter;

import com.zabra.zl.base.BasePresenter;
import com.zabra.zl.data.LoginBean;
import com.zabra.zl.data.SimpleBean;
import com.zabra.zl.net.RxScheduler;
import com.zabra.zl.ui.login.contract.LoginContract;
import com.zabra.zl.ui.login.model.LoginModel;

import io.reactivex.functions.Consumer;
import okhttp3.RequestBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class LoginPresenter extends BasePresenter<LoginContract.View> implements LoginContract.Presenter {
    private LoginContract.Model model;
    public LoginPresenter() {
        model=new LoginModel();
    }

    @Override
    public void getData(RequestBody body) {
        if (!isViewAttached()) {
            return;
        }
        mView.showLoading();
        model.getData(body).enqueue(new Callback<LoginBean>() {
            @Override
            public void onResponse(Call<LoginBean> call, Response<LoginBean> response) {
                mView.hideLoading();
                mView.onSuccess(response.body(),response.headers().get("token"));
            }

            @Override
            public void onFailure(Call<LoginBean> call, Throwable t) {
                mView.hideLoading();
                mView.onError(t);
            }
        });

    }
}
